package demo.standard;

import java.util.ArrayList;
import java.util.List;

public abstract class AbstractSubject {
    private List<IObserver> observers = new ArrayList<>();

    public void addObserver(IObserver observer) {
        System.out.println("添加观察者:" + observer.getClass().getSimpleName());
        observers.add(observer);
    }

    public void removeObserver(IObserver observer) {
        System.out.println("删除观察者:" + observer.getClass().getSimpleName());
        observers.remove(observer);
    }

    public void notifyAllObservers() {
        for (IObserver observer : observers) {
            observer.receiveNotify();
        }
    }
}
